<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>版本</title>
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/panel.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/window.css">
  <script type="text/javascript" src="<%=path %>/script/1.11.1.js"></script>
  <script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
  <script type="text/javascript" src="<%=path %>/script/dateFormat.js"></script>
  <script type="text/javascript" src="<%=path %>/script/datagrid-bufferview.js"></script>
  <script type="text/javascript" src="<%=path %>/script/common.js"></script>
  <style type="text/css">
    #fm{
      margin:0;
      padding:10px 30px;
    }
    .ftitle{
      font-size:14px;
      font-weight:bold;
      padding:5px 0;
      margin-bottom:10px;
      border-bottom:1px solid #ccc;
    }
    .fitem{
      margin-bottom:17px;
    }
    .fitem label{
      display:inline-block;
      width:80px;
    }
    .fitem input{
      width:230px;
    }
  </style>
</head>
<body>
<table id="tt" title="class" style="width:auto;height:800px">
</table>
<div id="toolbar" style="padding:5px;height:auto">
  <div>
     日期：<input id="day"  name="day" type="text" class="easyui-datebox" style="width:150px" />&nbsp;&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-search" onclick="searchVersion()">查询</a>
    <!-- 搜索条件结束 -->
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-add" onclick="newClass()">添加</a>&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-edit" onclick="editClass()">修改</a>&nbsp; 
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-remove" onclick="deleteClass()">删除</a>&nbsp;&nbsp;

  </div>
</div>



<!-- 添加/编辑框 开始-->
<div id="dlg" class="easyui-dialog"
     style="width: 500px; height: 450px; padding: 10px 20px" closed="true"
     buttons="#dlg-buttons">
  <div class="ftitle">版本信息</div>
  <form id="fm" method="post"  validate>
    <input type="hidden" name="id" id="cls_id" />
    <div class="fitem">
      <label>版本号:</label>
      <input  class="easyui-textbox" name="version" id="version" value=""/>
    </div>

    <div class="fitem">
      <label>平台:</label>
      <input class="easyui-combobox"  id="platformGuid" required
		name="platformGuid"
		data-options="
				url:'<%=basePath %>service/combo/platform',
				method:'get',
				valueField:'valueField',
				textField:'textField',
				panelHeight:'auto'
		">
    </div>
    <div class="fitem">
      <label>更新描述:</label>
      <textarea  style="overflow-y:visible;border:1;width:70%;height:60px;" name="description" required></textarea>
    </div>

    <div class="fitem" id="selectIsLatest">
      <label>是否最新:</label>
      <select  class="easyui-combobox" name="isLatest" id="isLatest" value="" panelHeight="auto" style="width:auto" disabled="disabled">
      	<option value="0">否</option>
      	<option value="1">是</option>
      </select>
      <input type="button"  onclick="setislatest();" value="设置为最新"/>
    </div> 
    <div class="fitem">
      <label>下载链接:</label>
      <input  class="easyui-textbox" name="downloadUrl" id="downloadUrl" value=""   required/>
    </div>
     <div class="fitem">
      <label>是否强制更新:</label>
      <select id="isForceUpdate" name="isForceUpdate" class="easyui-combobox"  panelHeight="auto" style="width:auto" data-options="editable:false" required>
		  <option value="0" selected="selected">否</option>
		  <option value="1">是</option>
	   </select>&nbsp;&nbsp;
    </div>
  </form>
  <div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6"
       iconCls="icon-ok" onclick="saveOrUpdateClass()" style="width: 90px">Save</a> <a
          href="javascript:void(0)" class="easyui-linkbutton"
          iconCls="icon-cancel" onclick="closeDialog()"
          style="width: 90px">Cancel</a>
  </div>
</div>

<!-- 添加/编辑框结束-->
<!-- sentence 添加/编辑框结束-->
<!-- ---------------------------------------------------------------------------------------------------------------------------------->
<!-- ---------------------------------------------------------------------------------------------------------------------------------->
<!-- ---------------------------------------------------------------------------------------------------------------------------------->


</body>
<script type="text/javascript">
  var class_id,course_id,gate_id;
  $.ajaxSetup({async : false});  
  $(function(){
    $('#tt').datagrid({
      url:'<%=basePath %>service/version/list?day=',
      method:'get',
      singleSelect:true,toolbar:'#toolbar',remoteSort:false,pageSize:50,nowrap:false,
      fitColumns:true,pagination:true,
      columns:[[
        {field:'id',title:'ID',sortable:true,width:20,hidden:true},
        {field:'name',title:'平台',sortable:true,width:35},
        {field:'version',title:'版本',sortable:true,width:35},
        {field:'description',title:'描述',sortable:true,width:150},
        {field:'isLatest',title:'是否最新',sortable:true,width:35,formatter:function(value,row,index){  
            if(value == "0"){
            	return "否";
            }else{
            	return "是";
            }
            }  
        }, 
        {field:'downloadUrl',title:'下载链接',sortable:true,width:150},
        {field:'platformGuid',title:'物理地址ID',sortable:true,width:100,hidden:true},
        {field:'isForceUpdate',title:'是否强制更新',sortable:true,width:35,formatter:function(value,row,index){  
            if(value == 0){
            	return "否";
            }
            if(value == 1){
            	return "是";
            }
            }  
        }, 
        {field:'createDate',title:'创建时间',sortable:true,width:60,formatter:function(value,row,index){  
            var unixTimestamp = new Date(value);  
            return unixTimestamp.toLocaleString();  
            }  
        },
        {field:'updateDate',title:'更新时间',sortable:true,width:60,formatter:function(value,row,index){  
          var unixTimestamp = new Date(value);  
          return unixTimestamp.toLocaleString();  
        }  
       }
      ]]
             
 })
   });
  function setislatest(){
	 var rowIndex=$('#tt').datagrid('getRowIndex',$('#tt').datagrid('getSelected')) 
	 var id = $("#cls_id").val();
	 var guid = $("#platformGuid").val();
	 $.ajaxSetup({async : false});
	 $.post("<%=basePath %>service/version/forceUpdate",{'id':id,'guid':guid},function(data){
		 if(data.status == 1){
	         $('#tt').datagrid('reload'); // reload the data
			 $('#dlg').dialog('close') ;
			 //$('#dlg').dialog('open').dialog('setTitle','编辑class');
	         //var row = $('#tt').datagrid('getData').rows[rowIndex];
			 //$('#fm').form('load',row);
			 return;
		 }else{
			 $.messager.alert("设置失败,请重新设置"+er);
			  return;
		 }
	});
  }
  function searchVersion(){
	  var day = $("#day").textbox("getValue");
		 var url = '<%=basePath %>service/version/list?day='+day;
		 $("#tt").datagrid({
			 url:'<%=basePath %>service/version/list?day='+day,
			 method:'get',
			 onLoadSuccess:function(data){
				 if(data.total == null){
					 $.messager.alert("提示","没有查询到任何符合条件的数据")
				 }
			 }
		 });
  }
  //关闭弹出框
  function closeDialog(){
    $('#dlg').dialog('close') ;
  }

  //添加class
  function newClass(){
	document.getElementById('selectIsLatest').style.display="none";
    $('#dlg').dialog('open').dialog('setTitle','添加版本');
    $('#fm').form('clear');
    url = '<%=basePath%>service/version/add';
  }

  function editClass(){
	document.getElementById('selectIsLatest').style.display="";
    url = '<%=basePath%>service/version/edit';
    var row = $('#tt').datagrid('getSelected');
    if (row){
      $("#cls_id").val(row.id);
      $("#version").val(row.version);
      $("#description").val(row.description);
      $("#isLatest").val(row.isLatest);
      $("#downloadUrl").val(row.downloadUrl);
      $("#platformGuid").val(row.platformGuid);
      $("#isForceUpdate").val(row.isForceUpdate);
      $('#dlg').dialog('open').dialog('setTitle','编辑class');
      $('#fm').form('load',row);
    }
  }


  function deleteClass(){

    var row = $('#tt').datagrid('getSelected');
    if (row){
      $.messager.confirm('提示','确定要删除这个class吗？',function(r){
        if (r){
          $.post('<%=basePath%>service/version/remove',{id:row.id},function(result){
            $('#tt').datagrid('reload');    // reload the data
          },'json');
        }
      });
    }
  }

  

  //添加或修改class
  function saveOrUpdateClass(){

    $('#fm').form('submit', {
      url : url,
      onSubmit : function() {
        return $(this).form('validate');
      },
      success : function(data) {
    	var result = eval("("+data+")");  
        if (result.status == -2) {
          $.messager.show({
            title : 'Error',
            msg : '服务器出错，请稍后再试'
          });
        }else if(result.status == -1){
        	$.messager.show({
        		title:'info',
        		msg:result.message
        	});
        }else {
          $('#dlg').dialog('close'); // close the dialog
          $('#tt').datagrid('reload'); // reload the data
        }
      }
    });
  }

   


  
 

  
 

 

  


 
  


 
  

 










</script>
</html>
